package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("增加图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("书的书名：");
        String name = scanner.nextLine();

        int ret = bookList.getUsedSize();
        for (int i = 0; i < ret; i++) {
            Book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)){
                System.out.println("已经有这本书！");
                return;
            }
        }

        System.out.println("书的作者：");
        String author = scanner.nextLine();
        System.out.println("书的类型：");
        String type = scanner.nextLine();
        System.out.println("书的价格：");
        int price = scanner.nextInt();
        Book book = new Book(name,author,type,price);

        bookList.setBooks(ret, book);
        bookList.setUsedSize(ret + 1);
        System.out.println("添加成功！");
    }
}
